package com.erp.order.controller;


import com.erp.order.domain.bo.ErpSendOutGoodsBo;
import com.erp.order.domain.vo.ErpSendOutGoodsVo;
import com.erp.order.service.IErpSendOutGoodsService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 订单发货
 *
 * @author erp
 * @date 2023-06-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/purchase/sendOutGoods")
public class ErpSendOutGoodsController extends BaseController {

    private final IErpSendOutGoodsService iErpSendOutGoodsService;



    @GetMapping("/querySendGoodsInfo")
    public R<Object> querySendGoodsInfo(ErpSendOutGoodsBo bo) {
        return R.ok(iErpSendOutGoodsService.querySendGoodsInfo(bo));
    }

    @GetMapping("/querySendGoodsInfoList")
    public R<Object> querySendGoodsInfoList(Long orderId) {
        return R.ok(iErpSendOutGoodsService.querySendGoodsInfoList(orderId));
    }

    /**
     * 查询订单发货列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSendOutGoodsVo> list(ErpSendOutGoodsBo bo, PageQuery pageQuery) {
        return iErpSendOutGoodsService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单发货详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSendOutGoodsVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long id) {
        return R.ok(iErpSendOutGoodsService.queryById(id));
    }

    /**
     * 新增订单发货
     */
    @Log(title = "订单发货", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSendOutGoodsBo bo) {
        return toAjax(iErpSendOutGoodsService.insertByBo(bo));
    }

    /**
     * 修改订单发货
     */
    @Log(title = "订单发货", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSendOutGoodsBo bo) {
        return toAjax(iErpSendOutGoodsService.updateByBo(bo));
    }

    /**
     * 删除订单发货
     *
     * @param ids 主键串
     */
    @Log(title = "订单发货", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSendOutGoodsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
